<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>fareyleni</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="fareylen.html" title="fareylen" />
    <link rel="next" href="ficlose.html" title="ficlose" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">fareyleni</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="fareylen.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="ficlose.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="fareyleni"></a>
      <div class="titlepage"></div>
      <a id="IndexFareyleni" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">fareyleni</span>
        </h2>
        <p>fareyleni — 
      returns the length of a Farey Sequence.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp102478128"></a>
        <h2>Description</h2>
        <p>
This opcode can be used in conjunction with <a class="link" href="GENfarey.html" title="GENfarey"><em class="citetitle">GENfarey</em></a>.
It calculates the length of Farey Sequence F<sub>n</sub>. Its length is given by:
|F<sub>n</sub>| = 1 + SUM over n phi(m) 
where phi(m) is Euler's totient function, which gives the number of integers ≤ m that are coprime to m.
    </p>
        <p>
      Some values for the length of F<sub>n</sub> given n:
      </p>
        <div class="informaltable">
          <table border="1">
            <colgroup>
              <col />
              <col />
            </colgroup>
            <thead>
              <tr>
                <th>n</th>
                <th>F<sub>n</sub></th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>1</td>
                <td>2</td>
              </tr>
              <tr>
                <td>2</td>
                <td>3</td>
              </tr>
              <tr>
                <td>3</td>
                <td>5</td>
              </tr>
              <tr>
                <td>4</td>
                <td>7</td>
              </tr>
              <tr>
                <td>5</td>
                <td>11</td>
              </tr>
              <tr>
                <td>6</td>
                <td>13</td>
              </tr>
              <tr>
                <td>7</td>
                <td>19</td>
              </tr>
              <tr>
                <td>8</td>
                <td>23</td>
              </tr>
              <tr>
                <td>9</td>
                <td>29</td>
              </tr>
              <tr>
                <td>10</td>
                <td>33</td>
              </tr>
              <tr>
                <td>11</td>
                <td>43</td>
              </tr>
              <tr>
                <td>12</td>
                <td>47</td>
              </tr>
              <tr>
                <td>13</td>
                <td>59</td>
              </tr>
              <tr>
                <td>14</td>
                <td>65</td>
              </tr>
              <tr>
                <td>15</td>
                <td>73</td>
              </tr>
              <tr>
                <td>16</td>
                <td>81</td>
              </tr>
              <tr>
                <td>17</td>
                <td>97</td>
              </tr>
              <tr>
                <td>18</td>
                <td>103</td>
              </tr>
              <tr>
                <td>19</td>
                <td>121</td>
              </tr>
              <tr>
                <td>20</td>
                <td>129</td>
              </tr>
            </tbody>
          </table>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp102508768"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ifl <span class="command"><strong>fareyleni</strong></span> ifn</pre>
      </div>
      <div class="refsect1">
        <a id="idp102510880"></a>
        <h2>Initialisation</h2>
        <p>
      The length of the identified Farey sequence is returned.
    </p>
        <p>
      <span class="emphasis"><em>ifn</em></span> -- Integer identifying the sequence.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp102513152"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the fareyleni opcode. It uses the file <a class="ulink" href="examples/fareyleni.csd" target="_top"><em class="citetitle">fareyleni.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp102515008"></a>
          <p class="title">
            <strong>Example 247. Example of the fareyleni opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc for RT audio input as well </span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o fareyleni.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

      <span class="comment">; initialise integer n for Farey Sequence F_8</span>
      gifarn <span class="opc">init</span> 8	

      <span class="comment">; calculate length of F_8, it should return 23 for |F_8|</span>
      gires <span class="opc">fareyleni</span> gifarn  

      <span class="comment">; convert to negative number for the GEN routine because</span>
      <span class="comment">; the table length won't be a power of 2 </span>
      <span class="comment">; (The length of a Farey Sequence of n &gt; 1 is always an odd number)</span>
      gilen <span class="opc">init</span> gires <span class="op">*</span> <span class="op">-</span>1 
      	   	       	               
      <span class="comment">; create F_8 with GENfarey, the negative table number prevents </span>
      <span class="comment">; unnecessary normalisation (F_8 IS already normalised)</span>
      <span class="comment">; 	         	    n  	   mode: </span>
      gifarey <span class="ohdr">ftgen</span> 100, 0, gilen, "farey", gifarn, 4
      <span class="comment">; if mode=4 then 1 is added to each element of F_n.</span>
      <span class="comment">; Useful for creating just tuning tables that can be read by the cps2pch opcode.</span>

<span class="oblock">instr</span> 1
      <span class="comment">; the very last element of F_n is not needed in the case of tuning tables</span>
      ires <span class="op">=</span> gires <span class="op">-</span> 1 
      <span class="comment">; read out and print to file</span>
      kndx <span class="opc">init</span> 0 
      <span class="octrl">if</span> (kndx <span class="op">&lt;</span> ires) then    
      	 kelem <span class="opc">tab</span> kndx, gifarey
      	 <span class="opc">fprintks</span> "farey8_tuning.txt", "<span class="op">%</span>2.6f\\n", kelem
      	 kndx <span class="op">=</span> kndx<span class="op">+</span>1
      <span class="octrl">endif</span>
      
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2

ip   <span class="opc">cps2pch</span> p4, <span class="op">-</span>100
asig <span class="opc">poscil</span> .5, ip, 1
aenv <span class="opc">linseg</span> 0, 0.1, 1, p3<span class="op">-</span>0.2, 1, 0.1, 0
     <span class="opc">outs</span> asig <span class="op">*</span> aenv, asig <span class="op">*</span> aenv

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>1 0 8192 10 1	<span class="comment">;sine wave</span>

<span class="stamnt">i</span>1	0     .1

<span class="stamnt">i</span>2	1	.5	8.00
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	.	&gt;
<span class="stamnt">i</span>2	+	1	8.22


<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp102519296"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Georg Boenn </td>
          </tr>
          <tr>
            <td>University of Glamorgan, UK</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound version 5.13</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="fareylen.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="ficlose.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">fareylen </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> ficlose</td>
        </tr>
      </table>
    </div>
  </body>
</html>
